﻿using BW.EatRabbit.API.Application.Commands.Provider;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MD5Hash;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Provider
{
    public class GetProviderQueryCommandHandler : IRequestHandler<GetProviderQueryCommand, APIResult<Provider_Information>>
    {
        private readonly IBaseRepository<Provider_Information> _provideRepository;
        public GetProviderQueryCommandHandler(IBaseRepository<Provider_Information> provideRepository)
        {
            _provideRepository = provideRepository;

        }
        public Task<APIResult<Provider_Information>> Handle(GetProviderQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<Provider_Information> result = new APIResult<Provider_Information>();
            var list= _provideRepository.GetAll().FirstOrDefault(x=>x.ProductionBatch==request.ProductionBatch);

          
            if (list == null)
            {
                result.Code = ResultCode.查询失败;
                result.Message = ResultCode.查询失败.ToString();

            }
            else
            {
                result.Code = ResultCode.查询成功;
                result.Message = ResultCode.查询成功.ToString();
                result.Data = list;
            }

            return Task.FromResult(result);
        }
    }
}
